/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DatosEcocardiogramaPanel.java
 *
 * Created on 17/01/2011, 17:22:06
 */

package presentacion.examen;

import hibernate.objeto.EcgEstudioCardiologia;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JDialog;
import javax.swing.JSpinner.DefaultEditor;
import logica.CapaLogica;
import presentacion.CapaPresentacion;
import presentacion.utilidad.maquetado.Fuente;

/**
 *
 * @author Gonzalo
 */
public class DatosECGPanel extends javax.swing.JPanel {

    /** Creates new form DatosEcocardiogramaPanel */
    public DatosECGPanel() {
        initComponents();
        setearEventosQueCapturanTeclaEnterYEscape();
    }

    /**
     * Setea datos de la ventana.
     *
     */
    public void personalizarJDialog(EcgEstudioCardiologia ecgEstudioCardiologia) {
        this.ecgEstudioCardiologia = ecgEstudioCardiologia;
            exhibirDatosEnPantalla();
            if(CapaPresentacion.modoVisualizacion) {
                inhabilitarCampos();
            }
    }

    /**
     * Permite visualizar los detalles de la evolución.
     *
     */
    private void exhibirDatosEnPantalla() {
        fCECG.setValue(ecgEstudioCardiologia.getFcEcgEstudioCardiologia());
        pRECG.setValue(ecgEstudioCardiologia.getPrEcgEstudioCardiologia());
        qRSECG.setValue(ecgEstudioCardiologia.getQrsEcgEstudioCardiologia());
        ejeECG.setValue(ecgEstudioCardiologia.getEjeEcgEstudioCardiologia());
        comentariosECG.setText(ecgEstudioCardiologia.
                getComentariosEcgEstudioCardiologia());
        comentariosECG.setCaretPosition(0);
    }

    /**
     * Pone en false la propiedad enabled de todos los campos de ingreso.
     *
     */
    private void inhabilitarCampos() {
        fCECG.setEnabled(false);
        pRECG.setEnabled(false);
        qRSECG.setEnabled(false);
        ejeECG.setEnabled(false);
        comentariosECG.setEnabled(false);
    }

    /**
     * Recopila los datos del panel para colocarlos dentro del arreglo.
     *
     * @param datosEstudioCardiologia El arreglo a cargar
     */
    public void recopilarDatos(Object[] datosEstudioCardiologia) {

        datosEstudioCardiologia[CapaLogica.ESTUDIO_CARDIOLOGIA_ECG_COMENTARIOS] =
                comentariosECG.getText();
        datosEstudioCardiologia[CapaLogica.ESTUDIO_CARDIOLOGIA_ECG_EJE] =
                ejeECG.getValue();
        datosEstudioCardiologia[CapaLogica.ESTUDIO_CARDIOLOGIA_ECG_FC] =
                fCECG.getValue();
        datosEstudioCardiologia[CapaLogica.ESTUDIO_CARDIOLOGIA_ECG_PR] =
                pRECG.getValue();
        datosEstudioCardiologia[CapaLogica.ESTUDIO_CARDIOLOGIA_ECG_QRS] =
                qRSECG.getValue();
    }

    /**
     * Setea en cada componente del JDialog los eventos que capturarán la tecla
     * enter y escape.
     */
    private void setearEventosQueCapturanTeclaEnterYEscape() {
        //Declaración del evento a capturar
        KeyListener keyListenerEscape = new KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
                    cerrarVentana();
                }
            }
        };

        //Setear eventos
        ((DefaultEditor) fCECG.getEditor()).
                getTextField().addKeyListener(keyListenerEscape);
        ((DefaultEditor) pRECG.getEditor()).
                getTextField().addKeyListener(keyListenerEscape);
        ((DefaultEditor) qRSECG.getEditor()).
                getTextField().addKeyListener(keyListenerEscape);
        ((DefaultEditor) ejeECG.getEditor()).
                getTextField().addKeyListener(keyListenerEscape);
        conclusionesECGScrollPane.addKeyListener(keyListenerEscape);
    }

    private void cerrarVentana() {
        JDialog jdialog = (JDialog)
                this.getParent().getParent().getParent().getParent().
                getParent().getParent().getParent().getParent().
                getParent().getParent().getParent().getParent().getParent();
        jdialog.dispose();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        textoFCECG = new javax.swing.JLabel();
        fCECG = new javax.swing.JSpinner();
        textoPRECG = new javax.swing.JLabel();
        pRECG = new javax.swing.JSpinner();
        ejeECG = new javax.swing.JSpinner();
        textoQRSECG = new javax.swing.JLabel();
        qRSECG = new javax.swing.JSpinner();
        textoEjeECG = new javax.swing.JLabel();
        textoComentariosECG = new javax.swing.JLabel();
        conclusionesECGScrollPane = new javax.swing.JScrollPane();
        comentariosECG = new javax.swing.JTextArea();

        textoFCECG.setFont(Fuente.FUENTE_LABEL);
        textoFCECG.setText("F.C.");
        textoFCECG.setPreferredSize(new java.awt.Dimension(233, 20));

        fCECG.setFont(Fuente.FUENTE_TEXTFIELD);
        fCECG.setModel(new javax.swing.SpinnerNumberModel());
        fCECG.setPreferredSize(new java.awt.Dimension(70, 20));

        textoPRECG.setFont(Fuente.FUENTE_LABEL);
        textoPRECG.setText("PR");
        textoPRECG.setPreferredSize(new java.awt.Dimension(233, 20));

        pRECG.setFont(Fuente.FUENTE_TEXTFIELD);
        pRECG.setModel(new javax.swing.SpinnerNumberModel());
        pRECG.setPreferredSize(new java.awt.Dimension(70, 20));

        ejeECG.setFont(Fuente.FUENTE_TEXTFIELD);
        ejeECG.setModel(new javax.swing.SpinnerNumberModel());
        ejeECG.setPreferredSize(new java.awt.Dimension(70, 20));

        textoQRSECG.setFont(Fuente.FUENTE_LABEL);
        textoQRSECG.setText("QRS");
        textoQRSECG.setPreferredSize(new java.awt.Dimension(233, 20));

        qRSECG.setFont(Fuente.FUENTE_TEXTFIELD);
        qRSECG.setModel(new javax.swing.SpinnerNumberModel());
        qRSECG.setPreferredSize(new java.awt.Dimension(70, 20));

        textoEjeECG.setFont(Fuente.FUENTE_LABEL);
        textoEjeECG.setText("Eje (grados)");
        textoEjeECG.setPreferredSize(new java.awt.Dimension(233, 20));

        textoComentariosECG.setFont(Fuente.FUENTE_LABEL);
        textoComentariosECG.setText("Comentarios");
        textoComentariosECG.setPreferredSize(new java.awt.Dimension(102, 20));

        conclusionesECGScrollPane.setPreferredSize(new java.awt.Dimension(286, 80));

        comentariosECG.setColumns(10);
        comentariosECG.setFont(Fuente.FUENTE_TEXTFIELD);
        comentariosECG.setRows(1);
        conclusionesECGScrollPane.setViewportView(comentariosECG);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(textoComentariosECG, 0, 0, Short.MAX_VALUE)
                    .addComponent(textoFCECG, 0, 0, Short.MAX_VALUE)
                    .addComponent(textoPRECG, 0, 0, Short.MAX_VALUE)
                    .addComponent(textoQRSECG, 0, 0, Short.MAX_VALUE)
                    .addComponent(textoEjeECG, javax.swing.GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(conclusionesECGScrollPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pRECG, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ejeECG, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(qRSECG, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(fCECG, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textoFCECG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(fCECG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textoPRECG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pRECG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textoQRSECG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(qRSECG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textoEjeECG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ejeECG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textoComentariosECG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(conclusionesECGScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea comentariosECG;
    private javax.swing.JScrollPane conclusionesECGScrollPane;
    private javax.swing.JSpinner ejeECG;
    private javax.swing.JSpinner fCECG;
    private javax.swing.JSpinner pRECG;
    private javax.swing.JSpinner qRSECG;
    private javax.swing.JLabel textoComentariosECG;
    private javax.swing.JLabel textoEjeECG;
    private javax.swing.JLabel textoFCECG;
    private javax.swing.JLabel textoPRECG;
    private javax.swing.JLabel textoQRSECG;
    // End of variables declaration//GEN-END:variables
    private EcgEstudioCardiologia ecgEstudioCardiologia;
}
